package game;

public class Collision {

	private Sprite object;
	private Direction side;
	
	public Collision(Sprite object, Direction side){
		this.object = object;
		this.side = side;
	}
	
	public static Direction getCollision(int sX1, int sY1, int sX2, int sY2,
			int spriteX1, int spriteY1, int spriteX2, int spriteY2){
		
		if (sX1 < spriteX2 && sX2 > spriteX1 && sY1 < spriteY2 && sY2 > spriteY1) {
					
			Direction side = null;
			
			double leftSide = Math.abs(sX1-spriteX2);
			double rightSide = Math.abs(sX2-spriteX1);
			double upSide = Math.abs(sY1-spriteY2);
			double downSide = Math.abs(sY2-spriteY1);
			
			double minSide = Math.min(leftSide, Math.min(rightSide, Math.min(upSide, downSide)));
			
			if (minSide==leftSide) side = Direction.RIGHT;
			if (minSide==rightSide) side = Direction.LEFT;
			if (minSide==upSide) side = Direction.DOWN;
			if (minSide==downSide) side = Direction.UP;									
			
			return side;
		}
		return null;
	}
	
	public Direction getSide() {
		return side;
	}
	
	public Sprite getObject() {
		return object;
	}
	
}
